import path from 'path'
import _debug from 'debug'

import { getRootPath } from '../utils'

const debug = _debug('build-tools:lint')

debug(
  'Config path from eslint webpack resolver:',
  path.join(__dirname, '../build/webpack.eslint.js'),
)

module.exports = {
  extends: ['airbnb', 'plugin:jest/recommended'],
  parser: 'babel-eslint',
  env: {
    es6: true,
    browser: true,
    node: true,
    jest: true,
  },
  plugins: ['react', 'babel', 'jest'],
  rules: {
    'class-methods-use-this': [
      'error',
      {
        exceptMethods: [
          'componentDidMount',
          'componentDidUpdate',
          'componentWillMount',
          'componentWillReceiveProps',
          'componentWillUnmount',
          'componentWillUpdate',
          'render',
          'shouldComponentUpdate',
        ],
      },
    ],
    semi: ['warn', 'never'],
    'arrow-parens': ['error', 'as-needed'],
    'no-unused-expressions': 'off',
    'no-underscore-dangle': 'off',
    'react/jsx-uses-vars': 'warn',
    'react/prefer-stateless-function': [
      'error',
      {
        ignorePureComponents: true,
      },
    ],
    'object-shorthand': 'warn',
    'generator-star-spacing': ['warn', 'after'],
    'import/no-named-as-default': 'off',
    'react/jsx-filename-extension': [
      'error',
      {
        extensions: ['.jsx', '.js'],
      },
    ],
    'jsx-a11y/no-static-element-interactions': 'off',
    'jsx-a11y/label-has-for': ['warn', ['label']],
  },
  settings: {
    'import/resolver': {
      node: {
        paths: [path.join(getRootPath(), 'src'), '.', 'node_modules'],
      },
      webpack: {
        config: path.join(__dirname, '../build/webpack.eslint'),
      },
    },
  },
}
